from indra.base import llsd
import urllib2
from urllib import urlencode
import simplejson

def caps_test():
    """test the caps server"""
    url="http://127.0.0.1:8080/_cap/grant"

    # We create a cap on my homepage
    grant={ 'region' : 'none',
            'key'    : 'jojo',
            'private-url' : 'http://mrtopf.de',
        }

    data = simplejson.dumps(grant)
    headers = {"Content-type": "application/json",
            "Accept": "*/*"}
    r = urllib2.Request(url,data,headers)
    res = urllib2.urlopen(r)
    payload = res.read()
    
    # now we got the data hopefully in json format and can decode it
    data = simplejson.loads(payload)
    
    # it should contain a public URL we can call which then retrieves my homepage
    print data['public-url']